﻿import idv.ben.gc4flash.chart.*;
import idv.ben.gc4flash.dataLine.*;
import idv.ben.gc4flash.encode.*;
import idv.ben.gc4flash.fill.*;
import idv.ben.gc4flash.util.*;
/**
* Linear gradient 填色方式，用來填圖形的背景色，或是整張圖片的背景色<br>
* 參考 Google Chart API：<a href="http://code.google.com/apis/chart/#linear_gradient" target="_blank">http://code.google.com/apis/chart/#linear_gradient</a><br>
*/
class idv.ben.gc4flash.fill.LinearGradientFill implements IFill {
	//<bg or c> is bg for background fill or c for chart area fill.
	private var fillArea:String;
	//<angle> specifies the angle of the gradient between 0 (horizontal) and 90 (vertical).
	private var angle:Number;
	//<color x> are RRGGBB format hexadecimal numbers.
	//<offset x> specify at what point the color is pure where: 0 specifies the right-most chart position and 1 the left-most.
	//[{color:"FFFFFF", offset:1 to 0}]
	private var colorSet:Array;
	/**
	* 建構子
	* @param fillArea 填色區域：
	* 		<ul>
	*		<li>{@link idv.ben.gc4flash.fill.FillType#FILL_TYPE_BG} = "bg"</li>
	*		<li>{@link idv.ben.gc4flash.fill.FillType#FILL_TYPE_CHART} = "c"</li>
	*		</ul>
	* @param angle 角度
	* @param colorSet 顏色字串組成的陣列，["顏色1", "顏色2", ..., "顏色n"]<br>
	* 		顏色字串，請參考 Google Chart API：<a href="http://code.google.com/apis/chart/#rgb" target="_blank">http://code.google.com/apis/chart/#rgb</a>
	*/
	//chf=<bg or c>,lg,<angle>,<color 1>,<offset 1>,<color n>,<offset n>
	function LinearGradientFill(fillArea:String, angle:Number, colorSet:Array) {
		this.fillArea = fillArea;
		this.angle = angle;
		this.colorSet = colorSet;
	}
	/**
	* 將填色設定，組成 URL 參數字串
	* <br>
	* <img src="http://chart.apis.google.com/chart?cht=lc&chd=s:pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp&chco=FF0000&chls=4.0,3.0,0.0&chs=200x125&chxt=x,y&chxl=0:|1|2|3|4|5|1:|0|50|100&chf=c,lg,0,76A4FB,1,ffffff,0|bg,s,EFEFEF"><br>
	* chf=c,lg,0,76A4FB,1,ffffff,0|bg,s,EFEFEF<br>
	* <br>
	* <img src="http://chart.apis.google.com/chart?cht=lc&chd=s:pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp&chco=FF0000&chls=4.0,3.0,0.0&chxt=x,y&chxl=0:|1|2|3|4|5|1:|0|50|100&chs=200x125&chf=c,lg,45,ffffff,0,76A4FB,0.75|bg,s,EFEFEF"><br>
	* chf=c,lg,45,ffffff,0,76A4FB,0.75|bg,s,EFEFEF<br>
	* <br>
	* <img src="http://chart.apis.google.com/chart?cht=lc&chd=s:pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp&chco=FF0000&chls=4.0,3.0,0.0&chs=200x125&chxt=x,y&chxl=0:|1|2|3|4|5|1:|0|50|100&chf=c,lg,90,76A4FB,0.5,ffffff,0|bg,s,EFEFEF"><br>
	* chf=c,lg,90,76A4FB,0.5,ffffff,0|bg,s,EFEFEF<br>
	* @return URL 參數字串
	*/
	function toChartData():String {
		var chartData:Array = new Array();
		for (var i:Number = 0; i<colorSet.length; i++) {
			chartData.push(colorSet[i].color+","+colorSet[i].offset);
		}
		return fillArea+",lg,"+angle+","+chartData.join(",");
	}
}
